
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/combinatorics/permutations.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:26:02 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Permutations &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="permutations.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Permutation Groups" href="perm_groups.html" />
    <link rel="prev" title="Partitions" href="partitions.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="perm_groups.html" title="Permutation Groups"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="partitions.html" title="Partitions"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Combinatorics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Permutations</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.combinatorics.permutations">
<span id="permutations"></span><span id="combinatorics-permutations"></span><h1>Permutations<a class="headerlink" href="#module-sympy.combinatorics.permutations" title="Permalink to this headline">¶</a></h1>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.permutations.</span></span><span class="sig-name descname"><span class="pre">Permutation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L471-L3010"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation" title="Permalink to this definition">¶</a></dt>
<dd><p>A permutation, alternatively known as an ‘arrangement number’ or ‘ordering’
is an arrangement of the elements of an ordered list into a one-to-one
mapping with itself. The permutation of a given arrangement is given by
indicating the positions of the elements after re-arrangement <a class="reference internal" href="#r64" id="id1"><span>[R64]</span></a>. For
example, if one started with elements [x, y, a, b] (in that order) and
they were reordered as [x, y, b, a] then the permutation would be
[0, 1, 3, 2]. Notice that (in SymPy) the first element is always referred
to as 0 and the permutation uses the indices of the elements in the
original ordering, not the elements (a, b, etc…) themselves.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p class="rubric">Permutations Notation</p>
<p>Permutations are commonly represented in disjoint cycle or array forms.</p>
<p class="rubric">Array Notation And 2-line Form</p>
<p>In the 2-line form, the elements and their final positions are shown
as a matrix with 2 rows:</p>
<p>[0    1    2     … n-1]
[p(0) p(1) p(2)  … p(n-1)]</p>
<p>Since the first line is always range(n), where n is the size of p,
it is sufficient to represent the permutation by the second line,
referred to as the “array form” of the permutation. This is entered
in brackets as the argument to the Permutation class:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]);</span> <span class="n">p</span>
<span class="go">Permutation([0, 2, 1])</span>
</pre></div>
</div>
<p>Given i in range(p.size), the permutation maps i to i^p</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">i</span><span class="o">^</span><span class="n">p</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">size</span><span class="p">)]</span>
<span class="go">[0, 2, 1]</span>
</pre></div>
</div>
<p>The composite of two permutations p*q means first apply p, then q, so
i^(p*q) = (i^p)^q which is i^p^q according to Python precedence rules:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">i</span><span class="o">^</span><span class="n">p</span><span class="o">^</span><span class="n">q</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span>
<span class="go">[2, 0, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">i</span><span class="o">^</span><span class="p">(</span><span class="n">p</span><span class="o">*</span><span class="n">q</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span>
<span class="go">[2, 0, 1]</span>
</pre></div>
</div>
<p>One can use also the notation p(i) = i^p, but then the composition
rule is (p*q)(i) = q(p(i)), not p(q(i)):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">[(</span><span class="n">p</span><span class="o">*</span><span class="n">q</span><span class="p">)(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">size</span><span class="p">)]</span>
<span class="go">[2, 0, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">q</span><span class="p">(</span><span class="n">p</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">size</span><span class="p">)]</span>
<span class="go">[2, 0, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">p</span><span class="p">(</span><span class="n">q</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">size</span><span class="p">)]</span>
<span class="go">[1, 2, 0]</span>
</pre></div>
</div>
<p class="rubric">Disjoint Cycle Notation</p>
<p>In disjoint cycle notation, only the elements that have shifted are
indicated. In the above case, the 2 and 1 switched places. This can
be entered in two ways:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="o">==</span> <span class="n">Permutation</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span> <span class="o">==</span> <span class="n">p</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Only the relative ordering of elements in a cycle matter:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>The disjoint cycle notation is convenient when representing
permutations that have several cycles in them:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span> <span class="o">==</span> <span class="n">Permutation</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">]])</span>
<span class="go">True</span>
</pre></div>
</div>
<p>It also provides some economy in entry when computing products of
permutations that are written in disjoint cycle notation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">)(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">Permutation([0, 3, 2, 1])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="o">==</span> <span class="n">Permutation</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]])</span><span class="o">*</span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span><span class="o">*</span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span>
<span class="go">True</span>
</pre></div>
</div>
<blockquote>
<div><p>Caution: when the cycles have common elements
between them then the order in which the
permutations are applied matters. The
convention is that the permutations are
applied from <em>right to left</em>. In the following, the
transposition of elements 2 and 3 is followed
by the transposition of elements 1 and 2:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="n">Permutation</span><span class="p">([(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)])</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
<span class="go">[0, 3, 1, 2]</span>
</pre></div>
</div>
<p>If the first and second elements had been
swapped first, followed by the swapping of the second
and third, the result would have been [0, 2, 3, 1].
If, for some reason, you want to apply the cycles
in the order they are entered, you can simply reverse
the order of cycles:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)][::</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
<span class="go">[0, 2, 3, 1]</span>
</pre></div>
</div>
</div></blockquote>
<p>Entering a singleton in a permutation is a way to indicate the size of the
permutation. The <code class="docutils literal notranslate"><span class="pre">size</span></code> keyword can also be used.</p>
<p>Array-form entry:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">9</span><span class="p">]])</span>
<span class="go">Permutation([0, 2, 1], size=10)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]],</span> <span class="n">size</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="go">Permutation([0, 2, 1], size=10)</span>
</pre></div>
</div>
<p>Cyclic-form entry:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="go">Permutation([0, 2, 1], size=10)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">9</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">Permutation([0, 2, 1], size=10)</span>
</pre></div>
</div>
<p>Caution: no singleton containing an element larger than the largest
in any previous cycle can be entered. This is an important difference
in how Permutation and Cycle handle the __call__ syntax. A singleton
argument at the start of a Permutation performs instantiation of the
Permutation and is permitted:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="go">Permutation([], size=6)</span>
</pre></div>
</div>
<p>A singleton entered after instantiation is a call to the permutation
– a function call – and if the argument is out of range it will
trigger an error. For this reason, it is better to start the cycle
with the singleton:</p>
<p>The following fails because there is no element 3:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">3</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">IndexError</span>: <span class="n">list index out of range</span>
</pre></div>
</div>
<p>This is ok: only the call to an out of range singleton is prohibited;
otherwise the permutation autosizes:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">3</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">Permutation([0, 2, 1, 3])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span> <span class="o">==</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">Equality Testing</p>
<p>The array forms must be the same in order for permutations to be equal:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span> <span class="o">==</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="go">False</span>
</pre></div>
</div>
<p class="rubric">Identity Permutation</p>
<p>The identity permutation is a permutation in which no element is out of
place. It can be entered in a variety of ways. All the following create
an identity permutation of size 4:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">I</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">all</span><span class="p">(</span><span class="n">p</span> <span class="o">==</span> <span class="n">I</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="p">[</span>
<span class="gp">... </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">3</span><span class="p">),</span>
<span class="gp">... </span><span class="n">Permutation</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)),</span>
<span class="gp">... </span><span class="n">Permutation</span><span class="p">([],</span> <span class="n">size</span><span class="o">=</span><span class="mi">4</span><span class="p">),</span>
<span class="gp">... </span><span class="n">Permutation</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">4</span><span class="p">)])</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Watch out for entering the range <em>inside</em> a set of brackets (which is
cycle notation):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">I</span> <span class="o">==</span> <span class="n">Permutation</span><span class="p">([</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)])</span>
<span class="go">False</span>
</pre></div>
</div>
<p class="rubric">Permutation Printing</p>
<p>There are a few things to note about how Permutations are printed.</p>
<p>1) If you prefer one form (array or cycle) over another, you can set
<code class="docutils literal notranslate"><span class="pre">init_printing</span></code> with the <code class="docutils literal notranslate"><span class="pre">perm_cyclic</span></code> flag.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">)(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span>
<span class="go">Permutation([0, 2, 1, 4, 5, 3])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span>
<span class="go">(1 2)(3 4 5)</span>
</pre></div>
</div>
<p>2) Regardless of the setting, a list of elements in the array for cyclic
form can be obtained and either of those can be copied and supplied as
the argument to Permutation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">array_form</span>
<span class="go">[0, 2, 1, 4, 5, 3]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">cyclic_form</span>
<span class="go">[[1, 2], [3, 4, 5]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="n">_</span><span class="p">)</span> <span class="o">==</span> <span class="n">p</span>
<span class="go">True</span>
</pre></div>
</div>
<p>3) Printing is economical in that as little as possible is printed while
retaining all information about the size of the permutation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="go">Permutation([1, 0, 2, 3])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>
<span class="go">Permutation([1, 0], size=20)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>
<span class="go">Permutation([1, 0, 2, 4, 3], size=20)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span>
<span class="go">(3)(0 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p>The 2 was not printed but it is still there as can be seen with the
array_form and size methods:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">array_form</span>
<span class="go">[1, 0, 2, 3]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">size</span>
<span class="go">4</span>
</pre></div>
</div>
<p class="rubric">Short Introduction To Other Methods</p>
<p>The permutation can act as a bijective function, telling what element is
located at a given position</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">array_form</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="c1"># the hard way</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c1"># the easy way</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">{</span><span class="n">i</span><span class="p">:</span> <span class="n">q</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">size</span><span class="p">)}</span> <span class="c1"># showing the bijection</span>
<span class="go">{0: 5, 1: 2, 2: 3, 3: 4, 4: 1, 5: 0}</span>
</pre></div>
</div>
<p>The full cyclic form (including singletons) can be obtained:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">full_cyclic_form</span>
<span class="go">[[0, 1], [2], [3]]</span>
</pre></div>
</div>
<p>Any permutation can be factored into transpositions of pairs of elements:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]])</span><span class="o">.</span><span class="n">transpositions</span><span class="p">()</span>
<span class="go">[(1, 2), (3, 5), (3, 4)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">rmul</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="n">Permutation</span><span class="p">([</span><span class="n">ti</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span> <span class="k">for</span> <span class="n">ti</span> <span class="ow">in</span> <span class="n">_</span><span class="p">])</span><span class="o">.</span><span class="n">cyclic_form</span>
<span class="go">[[1, 2], [3, 4, 5]]</span>
</pre></div>
</div>
<p>The number of permutations on a set of n elements is given by n! and is
called the cardinality.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">size</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">cardinality</span>
<span class="go">24</span>
</pre></div>
</div>
<p>A given permutation has a rank among all the possible permutations of the
same elements, but what that rank is depends on how the permutations are
enumerated. (There are a number of different methods of doing so.) The
lexicographic rank is given by the rank method and this rank is used to
increment a permutation with addition/subtraction:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank</span><span class="p">()</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">+</span> <span class="mi">1</span>
<span class="go">Permutation([1, 0, 3, 2])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">next_lex</span><span class="p">()</span>
<span class="go">Permutation([1, 0, 3, 2])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="o">.</span><span class="n">rank</span><span class="p">()</span>
<span class="go">7</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">unrank_lex</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">size</span><span class="p">,</span> <span class="n">rank</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>
<span class="go">Permutation([1, 0, 3, 2])</span>
</pre></div>
</div>
<p>The product of two permutations p and q is defined as their composition as
functions, (p*q)(i) = q(p(i)) <a class="reference internal" href="#r68" id="id2"><span>[R68]</span></a>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">q</span><span class="o">*</span><span class="n">p</span><span class="p">)</span>
<span class="go">[2, 3, 0, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">p</span><span class="o">*</span><span class="n">q</span><span class="p">)</span>
<span class="go">[3, 2, 1, 0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">q</span><span class="p">(</span><span class="n">p</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">size</span><span class="p">)]</span>
<span class="go">[3, 2, 1, 0]</span>
</pre></div>
</div>
<p>The permutation can be ‘applied’ to any list-like object, not only
Permutations:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">([</span><span class="s1">&#39;zero&#39;</span><span class="p">,</span> <span class="s1">&#39;one&#39;</span><span class="p">,</span> <span class="s1">&#39;four&#39;</span><span class="p">,</span> <span class="s1">&#39;two&#39;</span><span class="p">])</span>
<span class="go">[&#39;one&#39;, &#39;zero&#39;, &#39;four&#39;, &#39;two&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">(</span><span class="s1">&#39;zo42&#39;</span><span class="p">)</span>
<span class="go">[&#39;o&#39;, &#39;z&#39;, &#39;4&#39;, &#39;2&#39;]</span>
</pre></div>
</div>
<p>If you have a list of arbitrary elements, the corresponding permutation
can be found with the from_sequence method:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">from_sequence</span><span class="p">(</span><span class="s1">&#39;SymPy&#39;</span><span class="p">)</span>
<span class="go">Permutation([1, 3, 2, 0, 4])</span>
</pre></div>
</div>
<p class="rubric">Checking If A Permutation Is Contained In A Group</p>
<p>Generally if you have a group of permutations G on n symbols, and
you’re checking if a permutation on less than n symbols is part
of that group, the check will fail.</p>
<p>Here is an example for n=5 and we check if the cycle
(1,2,3) is in G:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Cycle</span><span class="p">,</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.perm_groups</span> <span class="kn">import</span> <span class="n">PermutationGroup</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">G</span> <span class="o">=</span> <span class="n">PermutationGroup</span><span class="p">(</span><span class="n">Cycle</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p1</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="n">Cycle</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p2</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a1</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="mi">6</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a2</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)(</span><span class="mi">5</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a3</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">),</span><span class="n">size</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="p">[</span><span class="n">p1</span><span class="p">,</span><span class="n">p2</span><span class="p">,</span><span class="n">a1</span><span class="p">,</span><span class="n">a2</span><span class="p">,</span><span class="n">a3</span><span class="p">]:</span> <span class="n">p</span><span class="p">,</span> <span class="n">G</span><span class="o">.</span><span class="n">contains</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="go">((2 5 3), True)</span>
<span class="go">((1 2 3), False)</span>
<span class="go">((5)(1 2 3), True)</span>
<span class="go">((5)(1 2 3), True)</span>
<span class="go">((5)(1 2 3), True)</span>
</pre></div>
</div>
<p>The check for p2 above will fail.</p>
<p>Checking if p1 is in G works because SymPy knows
G is a group on 5 symbols, and p1 is also on 5 symbols
(its largest element is 5).</p>
<p>For <code class="docutils literal notranslate"><span class="pre">a1</span></code>, the <code class="docutils literal notranslate"><span class="pre">.list(6)</span></code> call will extend the permutation to 5
symbols, so the test will work as well. In the case of <code class="docutils literal notranslate"><span class="pre">a2</span></code> the
permutation is being extended to 5 symbols by using a singleton,
and in the case of <code class="docutils literal notranslate"><span class="pre">a3</span></code> it’s extended through the constructor
argument <code class="docutils literal notranslate"><span class="pre">size=6</span></code>.</p>
<p>There is another way to do this, which is to tell the <code class="docutils literal notranslate"><span class="pre">contains</span></code>
method that the number of symbols the group is on doesn’t need to
match perfectly the number of symbols for the permutation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">G</span><span class="o">.</span><span class="n">contains</span><span class="p">(</span><span class="n">p2</span><span class="p">,</span><span class="n">strict</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>This can be via the <code class="docutils literal notranslate"><span class="pre">strict</span></code> argument to the <code class="docutils literal notranslate"><span class="pre">contains</span></code> method,
and SymPy will try to extend the permutation on its own and then
perform the containment check.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Cycle" title="sympy.combinatorics.permutations.Cycle"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Cycle</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r63"><span class="brackets"><a class="fn-backref" href="#id3">R63</a></span></dt>
<dd><p>Skiena, S. ‘Permutations.’ 1.1 in Implementing Discrete Mathematics
Combinatorics and Graph Theory with Mathematica.  Reading, MA:
Addison-Wesley, pp. 3-16, 1990.</p>
</dd>
<dt class="label" id="r64"><span class="brackets">R64</span><span class="fn-backref">(<a href="#id1">1</a>,<a href="#id4">2</a>)</span></dt>
<dd><p>Knuth, D. E. The Art of Computer Programming, Vol. 4: Combinatorial
Algorithms, 1st ed. Reading, MA: Addison-Wesley, 2011.</p>
</dd>
<dt class="label" id="r65"><span class="brackets"><a class="fn-backref" href="#id5">R65</a></span></dt>
<dd><p>Wendy Myrvold and Frank Ruskey. 2001. Ranking and unranking
permutations in linear time. Inf. Process. Lett. 79, 6 (September 2001),
281-284. DOI=10.1016/S0020-0190(01)00141-7</p>
</dd>
<dt class="label" id="r66"><span class="brackets"><a class="fn-backref" href="#id6">R66</a></span></dt>
<dd><p>D. L. Kreher, D. R. Stinson ‘Combinatorial Algorithms’
CRC Press, 1999</p>
</dd>
<dt class="label" id="r67"><span class="brackets"><a class="fn-backref" href="#id7">R67</a></span></dt>
<dd><p>Graham, R. L.; Knuth, D. E.; and Patashnik, O.
Concrete Mathematics: A Foundation for Computer Science, 2nd ed.
Reading, MA: Addison-Wesley, 1994.</p>
</dd>
<dt class="label" id="r68"><span class="brackets">R68</span><span class="fn-backref">(<a href="#id2">1</a>,<a href="#id8">2</a>)</span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Permutation#Product_and_inverse">https://en.wikipedia.org/wiki/Permutation#Product_and_inverse</a></p>
</dd>
<dt class="label" id="r69"><span class="brackets"><a class="fn-backref" href="#id9">R69</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Lehmer_code">https://en.wikipedia.org/wiki/Lehmer_code</a></p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.apply">
<span class="sig-name descname"><span class="pre">apply</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1662-L1709"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.apply" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply the permutation to an expression.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>i</strong> : Expr</p>
<blockquote>
<div><p>It should be an integer between <span class="math notranslate nohighlight">\(0\)</span> and <span class="math notranslate nohighlight">\(n-1\)</span> where <span class="math notranslate nohighlight">\(n\)</span>
is the size of the permutation.</p>
<p>If it is a symbol or a symbolic expression that can
have integer values, an <code class="docutils literal notranslate"><span class="pre">AppliedPermutation</span></code> object
will be returned which can represent an unevaluated
function.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>Any permutation can be defined as a bijective function
<span class="math notranslate nohighlight">\(\sigma : \{ 0, 1, ..., n-1 \} \rightarrow \{ 0, 1, ..., n-1 \}\)</span>
where <span class="math notranslate nohighlight">\(n\)</span> denotes the size of the permutation.</p>
<p>The definition may even be extended for any set with distinctive
elements, such that the permutation can even be applied for
real numbers or such, however, it is not implemented for now for
computational reasons and the integrity with the group theory
module.</p>
<p>This function is similar to the <code class="docutils literal notranslate"><span class="pre">__call__</span></code> magic, however,
<code class="docutils literal notranslate"><span class="pre">__call__</span></code> magic already has some other applications like
permuting an array or attatching new cycles, which would
not always be mathematically consistent.</p>
<p>This also guarantees that the return type is a SymPy integer,
which guarantees the safety to use assumptions.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.array_form">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">array_form</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.array_form" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a copy of the attribute _array_form
Examples
========</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">array_form</span>
<span class="go">[2, 3, 0, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span><span class="o">.</span><span class="n">array_form</span>
<span class="go">[3, 2, 0, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span><span class="o">.</span><span class="n">array_form</span>
<span class="go">[2, 0, 3, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]])</span><span class="o">.</span><span class="n">array_form</span>
<span class="go">[0, 2, 1, 3, 5, 4]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.ascents">
<span class="sig-name descname"><span class="pre">ascents</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2063-L2083"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.ascents" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the positions of ascents in a permutation, ie, the location
where p[i] &lt; p[i+1]</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">ascents</span><span class="p">()</span>
<span class="go">[1, 2]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.descents" title="sympy.combinatorics.permutations.Permutation.descents"><code class="xref py py-obj docutils literal notranslate"><span class="pre">descents</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.inversions" title="sympy.combinatorics.permutations.Permutation.inversions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inversions</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.min" title="sympy.combinatorics.permutations.Permutation.min"><code class="xref py py-obj docutils literal notranslate"><span class="pre">min</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.max" title="sympy.combinatorics.permutations.Permutation.max"><code class="xref py py-obj docutils literal notranslate"><span class="pre">max</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.atoms">
<span class="sig-name descname"><span class="pre">atoms</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1647-L1660"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.atoms" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns all the elements of a permutation</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span><span class="o">.</span><span class="n">atoms</span><span class="p">()</span>
<span class="go">{0, 1, 2, 3, 4, 5}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">]])</span><span class="o">.</span><span class="n">atoms</span><span class="p">()</span>
<span class="go">{0, 1, 2, 3, 4, 5}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.cardinality">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">cardinality</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.cardinality" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the number of all possible permutations.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">cardinality</span>
<span class="go">24</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.length" title="sympy.combinatorics.permutations.Permutation.length"><code class="xref py py-obj docutils literal notranslate"><span class="pre">length</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.order" title="sympy.combinatorics.permutations.Permutation.order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">order</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank" title="sympy.combinatorics.permutations.Permutation.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.size" title="sympy.combinatorics.permutations.Permutation.size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">size</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.commutator">
<span class="sig-name descname"><span class="pre">commutator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2215-L2262"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.commutator" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the commutator of <code class="docutils literal notranslate"><span class="pre">self</span></code> and <code class="docutils literal notranslate"><span class="pre">x</span></code>: <code class="docutils literal notranslate"><span class="pre">~x*~self*x*self</span></code></p>
<p>If f and g are part of a group, G, then the commutator of f and g
is the group identity iff f and g commute, i.e. fg == gf.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">commutator</span><span class="p">(</span><span class="n">x</span><span class="p">);</span> <span class="n">c</span>
<span class="go">Permutation([2, 1, 3, 0])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">==</span> <span class="o">~</span><span class="n">x</span><span class="o">*~</span><span class="n">p</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">p</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">I</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="p">[</span><span class="n">I</span> <span class="o">+</span> <span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">)):</span>
<span class="gp">... </span>    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">)):</span>
<span class="gp">... </span>        <span class="n">c</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">commutator</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">])</span>
<span class="gp">... </span>        <span class="k">if</span> <span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">*</span><span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="gp">... </span>            <span class="k">assert</span> <span class="n">c</span> <span class="o">==</span> <span class="n">I</span>
<span class="gp">... </span>        <span class="k">else</span><span class="p">:</span>
<span class="gp">... </span>            <span class="k">assert</span> <span class="n">c</span> <span class="o">!=</span> <span class="n">I</span>
<span class="gp">...</span>
</pre></div>
</div>
<p class="rubric">References</p>
<p><a class="reference external" href="https://en.wikipedia.org/wiki/Commutator">https://en.wikipedia.org/wiki/Commutator</a></p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.commutes_with">
<span class="sig-name descname"><span class="pre">commutes_with</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1364-L1382"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.commutes_with" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if the elements are commuting.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">commutes_with</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">commutes_with</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="go">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.cycle_structure">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">cycle_structure</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.cycle_structure" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the cycle structure of the permutation as a dictionary
indicating the multiplicity of each cycle length.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">cycle_structure</span>
<span class="go">{1: 4}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span><span class="o">.</span><span class="n">cycle_structure</span>
<span class="go">{2: 2, 3: 1}</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.cycles">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">cycles</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.cycles" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the number of cycles contained in the permutation
(including singletons).</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span><span class="o">.</span><span class="n">cycles</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span><span class="o">.</span><span class="n">full_cyclic_form</span>
<span class="go">[[0], [1], [2]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">cycles</span>
<span class="go">2</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../functions/combinatorial.html#sympy.functions.combinatorial.numbers.stirling" title="sympy.functions.combinatorial.numbers.stirling"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.functions.combinatorial.numbers.stirling</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.cyclic_form">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">cyclic_form</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.cyclic_form" title="Permalink to this definition">¶</a></dt>
<dd><p>This is used to convert to the cyclic notation
from the canonical notation. Singletons are omitted.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">cyclic_form</span>
<span class="go">[[1, 3, 2]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span><span class="o">.</span><span class="n">cyclic_form</span>
<span class="go">[[0, 1], [3, 4]]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.array_form" title="sympy.combinatorics.permutations.Permutation.array_form"><code class="xref py py-obj docutils literal notranslate"><span class="pre">array_form</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.full_cyclic_form" title="sympy.combinatorics.permutations.Permutation.full_cyclic_form"><code class="xref py py-obj docutils literal notranslate"><span class="pre">full_cyclic_form</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.descents">
<span class="sig-name descname"><span class="pre">descents</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2085-L2105"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.descents" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the positions of descents in a permutation, ie, the location
where p[i] &gt; p[i+1]</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">descents</span><span class="p">()</span>
<span class="go">[0, 3]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.ascents" title="sympy.combinatorics.permutations.Permutation.ascents"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ascents</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.inversions" title="sympy.combinatorics.permutations.Permutation.inversions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inversions</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.min" title="sympy.combinatorics.permutations.Permutation.min"><code class="xref py py-obj docutils literal notranslate"><span class="pre">min</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.max" title="sympy.combinatorics.permutations.Permutation.max"><code class="xref py py-obj docutils literal notranslate"><span class="pre">max</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.from_inversion_vector">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">from_inversion_vector</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">inversion</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2860-L2886"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.from_inversion_vector" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the permutation from the inversion vector.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">from_inversion_vector</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="go">Permutation([3, 2, 1, 0, 4, 5])</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.from_sequence">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">from_sequence</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">i</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">key</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1544-L1566"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.from_sequence" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the permutation needed to obtain <code class="docutils literal notranslate"><span class="pre">i</span></code> from the sorted
elements of <code class="docutils literal notranslate"><span class="pre">i</span></code>. If custom sorting is desired, a key can be given.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">from_sequence</span><span class="p">(</span><span class="s1">&#39;SymPy&#39;</span><span class="p">)</span>
<span class="go">(4)(0 1 3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="s2">&quot;SymPy&quot;</span><span class="p">))</span>
<span class="go">[&#39;S&#39;, &#39;y&#39;, &#39;m&#39;, &#39;P&#39;, &#39;y&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">from_sequence</span><span class="p">(</span><span class="s1">&#39;SymPy&#39;</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
<span class="go">(4)(0 2)(1 3)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.full_cyclic_form">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">full_cyclic_form</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.full_cyclic_form" title="Permalink to this definition">¶</a></dt>
<dd><p>Return permutation in cyclic form including singletons.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span><span class="o">.</span><span class="n">full_cyclic_form</span>
<span class="go">[[0], [1, 2]]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.get_adjacency_distance">
<span class="sig-name descname"><span class="pre">get_adjacency_distance</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2738-L2782"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.get_adjacency_distance" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the adjacency distance between two permutations.</p>
<p class="rubric">Explanation</p>
<p>This metric counts the number of times a pair i,j of jobs is
adjacent in both p and p’. If n_adj is this quantity then
the adjacency distance is n - n_adj - 1 [1]</p>
<p>[1] Reeves, Colin R. Landscapes, Operators and Heuristic search, Annals
of Operational Research, 86, pp 473-490. (1999)</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Permutation</span><span class="o">.</span><span class="n">josephus</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">get_adjacency_distance</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">get_adjacency_distance</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
<span class="go">4</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_precedence_matrix" title="sympy.combinatorics.permutations.Permutation.get_precedence_matrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_precedence_matrix</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_precedence_distance" title="sympy.combinatorics.permutations.Permutation.get_precedence_distance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_precedence_distance</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_adjacency_matrix" title="sympy.combinatorics.permutations.Permutation.get_adjacency_matrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_adjacency_matrix</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.get_adjacency_matrix">
<span class="sig-name descname"><span class="pre">get_adjacency_matrix</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2695-L2736"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.get_adjacency_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the adjacency matrix of a permutation.</p>
<p class="rubric">Explanation</p>
<p>If job i is adjacent to job j in a permutation p
then we set m[i, j] = 1 where m is the adjacency
matrix of p.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="o">.</span><span class="n">josephus</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">get_adjacency_matrix</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[0, 0, 0, 0, 0, 0],</span>
<span class="go">[0, 0, 0, 0, 1, 0],</span>
<span class="go">[0, 0, 0, 0, 0, 1],</span>
<span class="go">[0, 1, 0, 0, 0, 0],</span>
<span class="go">[1, 0, 0, 0, 0, 0],</span>
<span class="go">[0, 0, 0, 1, 0, 0]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">get_adjacency_matrix</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[0, 1, 0, 0],</span>
<span class="go">[0, 0, 1, 0],</span>
<span class="go">[0, 0, 0, 1],</span>
<span class="go">[0, 0, 0, 0]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_precedence_matrix" title="sympy.combinatorics.permutations.Permutation.get_precedence_matrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_precedence_matrix</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_precedence_distance" title="sympy.combinatorics.permutations.Permutation.get_precedence_distance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_precedence_distance</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_adjacency_distance" title="sympy.combinatorics.permutations.Permutation.get_adjacency_distance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_adjacency_distance</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.get_positional_distance">
<span class="sig-name descname"><span class="pre">get_positional_distance</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2784-L2809"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.get_positional_distance" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the positional distance between two permutations.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Permutation</span><span class="o">.</span><span class="n">josephus</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">get_positional_distance</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
<span class="go">12</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">get_positional_distance</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
<span class="go">12</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_precedence_distance" title="sympy.combinatorics.permutations.Permutation.get_precedence_distance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_precedence_distance</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_adjacency_distance" title="sympy.combinatorics.permutations.Permutation.get_adjacency_distance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_adjacency_distance</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.get_precedence_distance">
<span class="sig-name descname"><span class="pre">get_precedence_distance</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2654-L2693"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.get_precedence_distance" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the precedence distance between two permutations.</p>
<p class="rubric">Explanation</p>
<p>Suppose p and p’ represent n jobs. The precedence metric
counts the number of times a job j is preceded by job i
in both p and p’. This metric is commutative.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">get_precedence_distance</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
<span class="go">7</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">get_precedence_distance</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="go">7</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_precedence_matrix" title="sympy.combinatorics.permutations.Permutation.get_precedence_matrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_precedence_matrix</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_adjacency_matrix" title="sympy.combinatorics.permutations.Permutation.get_adjacency_matrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_adjacency_matrix</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_adjacency_distance" title="sympy.combinatorics.permutations.Permutation.get_adjacency_distance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_adjacency_distance</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.get_precedence_matrix">
<span class="sig-name descname"><span class="pre">get_precedence_matrix</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2619-L2652"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.get_precedence_matrix" title="Permalink to this definition">¶</a></dt>
<dd><p>Gets the precedence matrix. This is used for computing the
distance between two permutations.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="o">.</span><span class="n">josephus</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span>
<span class="go">Permutation([2, 5, 3, 1, 4, 0])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">get_precedence_matrix</span><span class="p">()</span>
<span class="go">Matrix([</span>
<span class="go">[0, 0, 0, 0, 0, 0],</span>
<span class="go">[1, 0, 0, 0, 1, 0],</span>
<span class="go">[1, 1, 0, 1, 1, 1],</span>
<span class="go">[1, 1, 0, 0, 1, 0],</span>
<span class="go">[1, 0, 0, 0, 0, 0],</span>
<span class="go">[1, 1, 0, 1, 1, 0]])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_precedence_distance" title="sympy.combinatorics.permutations.Permutation.get_precedence_distance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_precedence_distance</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_adjacency_matrix" title="sympy.combinatorics.permutations.Permutation.get_adjacency_matrix"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_adjacency_matrix</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.get_adjacency_distance" title="sympy.combinatorics.permutations.Permutation.get_adjacency_distance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_adjacency_distance</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.index">
<span class="sig-name descname"><span class="pre">index</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2393-L2410"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.index" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the index of a permutation.</p>
<p>The index of a permutation is the sum of all subscripts j such
that p[j] is greater than p[j+1].</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">index</span><span class="p">()</span>
<span class="go">2</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.inversion_vector">
<span class="sig-name descname"><span class="pre">inversion_vector</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2432-L2482"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.inversion_vector" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the inversion vector of the permutation.</p>
<p>The inversion vector consists of elements whose value
indicates the number of elements in the permutation
that are lesser than it and lie on its right hand side.</p>
<p>The inversion vector is the same as the Lehmer encoding of a
permutation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">inversion_vector</span><span class="p">()</span>
<span class="go">[4, 7, 0, 5, 0, 2, 1, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">inversion_vector</span><span class="p">()</span>
<span class="go">[3, 2, 1]</span>
</pre></div>
</div>
<p>The inversion vector increases lexicographically with the rank
of the permutation, the -ith element cycling through 0..i.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">while</span> <span class="n">p</span><span class="p">:</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">inversion_vector</span><span class="p">(),</span> <span class="n">p</span><span class="o">.</span><span class="n">rank</span><span class="p">()))</span>
<span class="gp">... </span>    <span class="n">p</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">next_lex</span><span class="p">()</span>
<span class="go">(2) [0, 0] 0</span>
<span class="go">(1 2) [0, 1] 1</span>
<span class="go">(2)(0 1) [1, 0] 2</span>
<span class="go">(0 1 2) [1, 1] 3</span>
<span class="go">(0 2 1) [2, 0] 4</span>
<span class="go">(0 2) [2, 1] 5</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.from_inversion_vector" title="sympy.combinatorics.permutations.Permutation.from_inversion_vector"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_inversion_vector</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.inversions">
<span class="sig-name descname"><span class="pre">inversions</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2155-L2213"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.inversions" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the number of inversions of a permutation.</p>
<p class="rubric">Explanation</p>
<p>An inversion is where i &gt; j but p[i] &lt; p[j].</p>
<p>For small length of p, it iterates over all i and j
values and calculates the number of inversions.
For large length of p, it uses a variation of merge
sort to calculate the number of inversions.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">inversions</span><span class="p">()</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">inversions</span><span class="p">()</span>
<span class="go">6</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.descents" title="sympy.combinatorics.permutations.Permutation.descents"><code class="xref py py-obj docutils literal notranslate"><span class="pre">descents</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.ascents" title="sympy.combinatorics.permutations.Permutation.ascents"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ascents</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.min" title="sympy.combinatorics.permutations.Permutation.min"><code class="xref py py-obj docutils literal notranslate"><span class="pre">min</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.max" title="sympy.combinatorics.permutations.Permutation.max"><code class="xref py py-obj docutils literal notranslate"><span class="pre">max</span></code></a></p>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r70"><span class="brackets"><a class="fn-backref" href="#id10">R70</a></span></dt>
<dd><p><a class="reference external" href="http://www.cp.eng.chula.ac.th/~piak/teaching/algo/algo2008/count-inv.htm">http://www.cp.eng.chula.ac.th/~piak/teaching/algo/algo2008/count-inv.htm</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.is_Empty">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_Empty</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.is_Empty" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks to see if the permutation is a set with zero elements</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([])</span><span class="o">.</span><span class="n">is_Empty</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">is_Empty</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.is_Singleton" title="sympy.combinatorics.permutations.Permutation.is_Singleton"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_Singleton</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.is_Identity">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_Identity</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.is_Identity" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns True if the Permutation is an identity permutation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">is_Identity</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([[</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">is_Identity</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">is_Identity</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">is_Identity</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.order" title="sympy.combinatorics.permutations.Permutation.order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">order</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.is_Singleton">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_Singleton</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.is_Singleton" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks to see if the permutation contains only one number and is
thus the only possible permutation of this set of numbers</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">is_Singleton</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span><span class="o">.</span><span class="n">is_Singleton</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.is_Empty" title="sympy.combinatorics.permutations.Permutation.is_Empty"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_Empty</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.is_even">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_even</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.is_even" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if a permutation is even.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">is_even</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">is_even</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.is_odd" title="sympy.combinatorics.permutations.Permutation.is_odd"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_odd</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.is_odd">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">is_odd</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.is_odd" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if a permutation is odd.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">is_odd</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">is_odd</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.is_even" title="sympy.combinatorics.permutations.Permutation.is_even"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_even</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.josephus">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">josephus</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">m</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">s</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2811-L2858"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.josephus" title="Permalink to this definition">¶</a></dt>
<dd><p>Return as a permutation the shuffling of range(n) using the Josephus
scheme in which every m-th item is selected until all have been chosen.
The returned permutation has elements listed by the order in which they
were selected.</p>
<p>The parameter <code class="docutils literal notranslate"><span class="pre">s</span></code> stops the selection process when there are <code class="docutils literal notranslate"><span class="pre">s</span></code>
items remaining and these are selected by continuing the selection,
counting by 1 rather than by <code class="docutils literal notranslate"><span class="pre">m</span></code>.</p>
<p>Consider selecting every 3rd item from 6 until only 2 remain:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">choices</span>    <span class="n">chosen</span>
<span class="o">========</span>   <span class="o">======</span>
  <span class="mi">012345</span>
  <span class="mi">01</span> <span class="mi">345</span>   <span class="mi">2</span>
  <span class="mi">01</span> <span class="mi">34</span>    <span class="mi">25</span>
  <span class="mi">01</span>  <span class="mi">4</span>    <span class="mi">253</span>
  <span class="mi">0</span>   <span class="mi">4</span>    <span class="mi">2531</span>
  <span class="mi">0</span>        <span class="mi">25314</span>
           <span class="mi">253140</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">josephus</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">array_form</span>
<span class="go">[2, 5, 3, 1, 4, 0]</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r71"><span class="brackets"><a class="fn-backref" href="#id11">R71</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Flavius_Josephus">https://en.wikipedia.org/wiki/Flavius_Josephus</a></p>
</dd>
<dt class="label" id="r72"><span class="brackets"><a class="fn-backref" href="#id12">R72</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Josephus_problem">https://en.wikipedia.org/wiki/Josephus_problem</a></p>
</dd>
<dt class="label" id="r73"><span class="brackets"><a class="fn-backref" href="#id13">R73</a></span></dt>
<dd><p><a class="reference external" href="http://www.wou.edu/~burtonl/josephus.html">http://www.wou.edu/~burtonl/josephus.html</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.length">
<span class="sig-name descname"><span class="pre">length</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2322-L2341"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.length" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the number of integers moved by a permutation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span><span class="o">.</span><span class="n">length</span><span class="p">()</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]])</span><span class="o">.</span><span class="n">length</span><span class="p">()</span>
<span class="go">4</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.min" title="sympy.combinatorics.permutations.Permutation.min"><code class="xref py py-obj docutils literal notranslate"><span class="pre">min</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.max" title="sympy.combinatorics.permutations.Permutation.max"><code class="xref py py-obj docutils literal notranslate"><span class="pre">max</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.support" title="sympy.combinatorics.permutations.Permutation.support"><code class="xref py py-obj docutils literal notranslate"><span class="pre">support</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.cardinality" title="sympy.combinatorics.permutations.Permutation.cardinality"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cardinality</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.order" title="sympy.combinatorics.permutations.Permutation.order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">order</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank" title="sympy.combinatorics.permutations.Permutation.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.size" title="sympy.combinatorics.permutations.Permutation.size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">size</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.list">
<span class="sig-name descname"><span class="pre">list</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1060-L1098"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.list" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the permutation as an explicit list, possibly
trimming unmoved elements if size is less than the maximum
element in the permutation; if this is desired, setting
<code class="docutils literal notranslate"><span class="pre">size=-1</span></code> will guarantee such trimming.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
<span class="go">[0, 1, 3, 2, 5, 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">[0, 1, 3, 2, 5, 4, 6, 7, 8, 9]</span>
</pre></div>
</div>
<p>Passing a length too small will trim trailing, unchanged elements
in the permutation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">[0, 2, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">[]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.max">
<span class="sig-name descname"><span class="pre">max</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2107-L2129"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.max" title="Permalink to this definition">¶</a></dt>
<dd><p>The maximum element moved by the permutation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.min" title="sympy.combinatorics.permutations.Permutation.min"><code class="xref py py-obj docutils literal notranslate"><span class="pre">min</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.descents" title="sympy.combinatorics.permutations.Permutation.descents"><code class="xref py py-obj docutils literal notranslate"><span class="pre">descents</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.ascents" title="sympy.combinatorics.permutations.Permutation.ascents"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ascents</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.inversions" title="sympy.combinatorics.permutations.Permutation.inversions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inversions</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.min">
<span class="sig-name descname"><span class="pre">min</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2131-L2153"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.min" title="Permalink to this definition">¶</a></dt>
<dd><p>The minimum element moved by the permutation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
<span class="go">2</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.max" title="sympy.combinatorics.permutations.Permutation.max"><code class="xref py py-obj docutils literal notranslate"><span class="pre">max</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.descents" title="sympy.combinatorics.permutations.Permutation.descents"><code class="xref py py-obj docutils literal notranslate"><span class="pre">descents</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.ascents" title="sympy.combinatorics.permutations.Permutation.ascents"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ascents</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.inversions" title="sympy.combinatorics.permutations.Permutation.inversions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inversions</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.mul_inv">
<span class="sig-name descname"><span class="pre">mul_inv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1286-L1292"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.mul_inv" title="Permalink to this definition">¶</a></dt>
<dd><p>other*~self, self and other have _array_form</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.next_lex">
<span class="sig-name descname"><span class="pre">next_lex</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1711-L1752"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.next_lex" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the next permutation in lexicographical order.
If self is the last permutation in lexicographical order
it returns None.
See [4] section 2.4.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]);</span> <span class="n">p</span><span class="o">.</span><span class="n">rank</span><span class="p">()</span>
<span class="go">17</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">next_lex</span><span class="p">();</span> <span class="n">p</span><span class="o">.</span><span class="n">rank</span><span class="p">()</span>
<span class="go">18</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank" title="sympy.combinatorics.permutations.Permutation.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.unrank_lex" title="sympy.combinatorics.permutations.Permutation.unrank_lex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">unrank_lex</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.next_nonlex">
<span class="sig-name descname"><span class="pre">next_nonlex</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1823-L1849"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.next_nonlex" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the next permutation in nonlex order [3].
If self is the last permutation in this order it returns None.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">]);</span> <span class="n">p</span><span class="o">.</span><span class="n">rank_nonlex</span><span class="p">()</span>
<span class="go">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">next_nonlex</span><span class="p">();</span> <span class="n">p</span>
<span class="go">Permutation([3, 0, 1, 2])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank_nonlex</span><span class="p">()</span>
<span class="go">6</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank_nonlex" title="sympy.combinatorics.permutations.Permutation.rank_nonlex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank_nonlex</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.unrank_nonlex" title="sympy.combinatorics.permutations.Permutation.unrank_nonlex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">unrank_nonlex</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.next_trotterjohnson">
<span class="sig-name descname"><span class="pre">next_trotterjohnson</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2564-L2617"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.next_trotterjohnson" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the next permutation in Trotter-Johnson order.
If self is the last permutation it returns None.
See [4] section 2.4. If it is desired to generate all such
permutations, they can be generated in order more quickly
with the <code class="docutils literal notranslate"><span class="pre">generate_bell</span></code> function.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank_trotterjohnson</span><span class="p">()</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">next_trotterjohnson</span><span class="p">();</span> <span class="n">p</span>
<span class="go">Permutation([0, 3, 2, 1])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank_trotterjohnson</span><span class="p">()</span>
<span class="go">5</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank_trotterjohnson" title="sympy.combinatorics.permutations.Permutation.rank_trotterjohnson"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank_trotterjohnson</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.unrank_trotterjohnson" title="sympy.combinatorics.permutations.Permutation.unrank_trotterjohnson"><code class="xref py py-obj docutils literal notranslate"><span class="pre">unrank_trotterjohnson</span></code></a>, <a class="reference internal" href="../utilities/iterables.html#sympy.utilities.iterables.generate_bell" title="sympy.utilities.iterables.generate_bell"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.utilities.iterables.generate_bell</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.order">
<span class="sig-name descname"><span class="pre">order</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2295-L2320"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.order" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the order of a permutation.</p>
<p>When the permutation is raised to the power of its
order it equals the identity permutation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">order</span><span class="p">()</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">p</span><span class="o">**</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">order</span><span class="p">()))</span>
<span class="go">Permutation([], size=6)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="perm_groups.html#sympy.combinatorics.perm_groups.PermutationGroup.identity" title="sympy.combinatorics.perm_groups.PermutationGroup.identity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">identity</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.cardinality" title="sympy.combinatorics.permutations.Permutation.cardinality"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cardinality</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.length" title="sympy.combinatorics.permutations.Permutation.length"><code class="xref py py-obj docutils literal notranslate"><span class="pre">length</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank" title="sympy.combinatorics.permutations.Permutation.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.size" title="sympy.combinatorics.permutations.Permutation.size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">size</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.parity">
<span class="sig-name descname"><span class="pre">parity</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1908-L1938"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.parity" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the parity of a permutation.</p>
<p class="rubric">Explanation</p>
<p>The parity of a permutation reflects the parity of the
number of inversions in the permutation, i.e., the
number of pairs of x and y such that <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">&gt;</span> <span class="pre">y</span></code> but <code class="docutils literal notranslate"><span class="pre">p[x]</span> <span class="pre">&lt;</span> <span class="pre">p[y]</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">parity</span><span class="p">()</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">parity</span><span class="p">()</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations._af_parity" title="sympy.combinatorics.permutations._af_parity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">_af_parity</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.random">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">random</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2888-L2905"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.random" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates a random permutation of length <code class="docutils literal notranslate"><span class="pre">n</span></code>.</p>
<p>Uses the underlying Python pseudo-random number generator.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">random</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="ow">in</span> <span class="p">(</span><span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]),</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.rank">
<span class="sig-name descname"><span class="pre">rank</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1851-L1886"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.rank" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the lexicographic rank of the permutation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank</span><span class="p">()</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank</span><span class="p">()</span>
<span class="go">23</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.next_lex" title="sympy.combinatorics.permutations.Permutation.next_lex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next_lex</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.unrank_lex" title="sympy.combinatorics.permutations.Permutation.unrank_lex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">unrank_lex</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.cardinality" title="sympy.combinatorics.permutations.Permutation.cardinality"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cardinality</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.length" title="sympy.combinatorics.permutations.Permutation.length"><code class="xref py py-obj docutils literal notranslate"><span class="pre">length</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.order" title="sympy.combinatorics.permutations.Permutation.order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">order</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.size" title="sympy.combinatorics.permutations.Permutation.size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">size</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.rank_nonlex">
<span class="sig-name descname"><span class="pre">rank_nonlex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">inv_perm</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1787-L1821"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.rank_nonlex" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a linear time ranking algorithm that does not
enforce lexicographic order [3].</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank_nonlex</span><span class="p">()</span>
<span class="go">23</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.next_nonlex" title="sympy.combinatorics.permutations.Permutation.next_nonlex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next_nonlex</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.unrank_nonlex" title="sympy.combinatorics.permutations.Permutation.unrank_nonlex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">unrank_nonlex</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.rank_trotterjohnson">
<span class="sig-name descname"><span class="pre">rank_trotterjohnson</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2484-L2524"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.rank_trotterjohnson" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the Trotter Johnson rank, which we get from the minimal
change algorithm. See [4] section 2.4.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank_trotterjohnson</span><span class="p">()</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">rank_trotterjohnson</span><span class="p">()</span>
<span class="go">7</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.unrank_trotterjohnson" title="sympy.combinatorics.permutations.Permutation.unrank_trotterjohnson"><code class="xref py py-obj docutils literal notranslate"><span class="pre">unrank_trotterjohnson</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.next_trotterjohnson" title="sympy.combinatorics.permutations.Permutation.next_trotterjohnson"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next_trotterjohnson</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.resize">
<span class="sig-name descname"><span class="pre">resize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2942-L3007"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.resize" title="Permalink to this definition">¶</a></dt>
<dd><p>Resize the permutation to the new size <code class="docutils literal notranslate"><span class="pre">n</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>n</strong> : int</p>
<blockquote>
<div><p>The new size of the permutation.</p>
</div></blockquote>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><p><strong>ValueError</strong></p>
<blockquote>
<div><p>If the permutation cannot be resized to the given size.
This may only happen when resized to a smaller size than
the original.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
</pre></div>
</div>
<p>Increasing the size of a permutation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">resize</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span>
<span class="go">(4)(0 1 2)</span>
</pre></div>
</div>
<p>Decreasing the size of the permutation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">resize</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span>
<span class="go">(3)(0 1 2)</span>
</pre></div>
</div>
<p>If resizing to the specific size breaks the cycles:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">resize</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">ValueError</span>: <span class="n">The permutation can not be resized to 2 because the</span>
<span class="go">cycle (0, 1, 2) may break.</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.rmul">
<em class="property"><span class="pre">static</span> </em><span class="sig-name descname"><span class="pre">rmul</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1231-L1274"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.rmul" title="Permalink to this definition">¶</a></dt>
<dd><p>Return product of Permutations [a, b, c, …] as the Permutation whose
ith value is a(b(c(i))).</p>
<p>a, b, c, … can be Permutation objects or tuples.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="n">a</span><span class="p">);</span> <span class="n">b</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">Permutation</span><span class="o">.</span><span class="n">rmul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span>
<span class="go">[1, 2, 0]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">a</span><span class="p">(</span><span class="n">b</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span>
<span class="go">[1, 2, 0]</span>
</pre></div>
</div>
<p>This handles the operands in reverse order compared to the <code class="docutils literal notranslate"><span class="pre">*</span></code> operator:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="n">a</span><span class="p">);</span> <span class="n">b</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">a</span><span class="o">*</span><span class="n">b</span><span class="p">)</span>
<span class="go">[2, 0, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">b</span><span class="p">(</span><span class="n">a</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">)]</span>
<span class="go">[2, 0, 1]</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>All items in the sequence will be parsed by Permutation as
necessary as long as the first item is a Permutation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">rmul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="o">==</span> <span class="n">Permutation</span><span class="o">.</span><span class="n">rmul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<p>The reverse order of arguments will raise a TypeError.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.rmul_with_af">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">rmul_with_af</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1276-L1284"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.rmul_with_af" title="Permalink to this definition">¶</a></dt>
<dd><p>same as rmul, but the elements of args are Permutation objects
which have _array_form</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.runs">
<span class="sig-name descname"><span class="pre">runs</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2412-L2430"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.runs" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the runs of a permutation.</p>
<p>An ascending sequence in a permutation is called a run [5].</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">8</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">runs</span><span class="p">()</span>
<span class="go">[[2, 5, 7], [3, 6], [0, 1, 4, 8]]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">runs</span><span class="p">()</span>
<span class="go">[[1, 3], [2], [0]]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.signature">
<span class="sig-name descname"><span class="pre">signature</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2264-L2293"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.signature" title="Permalink to this definition">¶</a></dt>
<dd><p>Gives the signature of the permutation needed to place the
elements of the permutation in canonical order.</p>
<p>The signature is calculated as (-1)^&lt;number of inversions&gt;</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">inversions</span><span class="p">()</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">signature</span><span class="p">()</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">inversions</span><span class="p">()</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">q</span><span class="o">.</span><span class="n">signature</span><span class="p">()</span>
<span class="go">-1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.inversions" title="sympy.combinatorics.permutations.Permutation.inversions"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inversions</span></code></a></p>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.size">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">size</span></span><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.size" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the number of elements in the permutation.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="p">([[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span><span class="o">.</span><span class="n">size</span>
<span class="go">4</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.cardinality" title="sympy.combinatorics.permutations.Permutation.cardinality"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cardinality</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.length" title="sympy.combinatorics.permutations.Permutation.length"><code class="xref py py-obj docutils literal notranslate"><span class="pre">length</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.order" title="sympy.combinatorics.permutations.Permutation.order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">order</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank" title="sympy.combinatorics.permutations.Permutation.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.support">
<span class="sig-name descname"><span class="pre">support</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1179-L1193"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.support" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the elements in permutation, P, for which P[i] != i.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">array_form</span>
<span class="go">[1, 0, 3, 2, 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">support</span><span class="p">()</span>
<span class="go">[0, 1, 2, 3]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.transpositions">
<span class="sig-name descname"><span class="pre">transpositions</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1503-L1542"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.transpositions" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the permutation decomposed into a list of transpositions.</p>
<p class="rubric">Explanation</p>
<p>It is always possible to express a permutation as the product of
transpositions, see [1]</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Permutation</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">transpositions</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span>
<span class="go">[(0, 7), (0, 6), (0, 5), (0, 4), (1, 3), (1, 2)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">t</span><span class="p">))</span>
<span class="go">(0, 7)(0, 6)(0, 5)(0, 4)(1, 3)(1, 2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">rmul</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="n">Permutation</span><span class="p">([</span><span class="n">ti</span><span class="p">],</span> <span class="n">size</span><span class="o">=</span><span class="n">p</span><span class="o">.</span><span class="n">size</span><span class="p">)</span> <span class="k">for</span> <span class="n">ti</span> <span class="ow">in</span> <span class="n">t</span><span class="p">])</span> <span class="o">==</span> <span class="n">p</span>
<span class="go">True</span>
</pre></div>
</div>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r74"><span class="brackets"><a class="fn-backref" href="#id14">R74</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Transposition_(mathematics)#Properties">https://en.wikipedia.org/wiki/Transposition_%28mathematics%29#Properties</a></p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.unrank_lex">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">unrank_lex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rank</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2907-L2940"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.unrank_lex" title="Permalink to this definition">¶</a></dt>
<dd><p>Lexicographic permutation unranking.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Permutation</span><span class="o">.</span><span class="n">unrank_lex</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">rank</span><span class="p">()</span>
<span class="go">10</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span>
<span class="go">Permutation([0, 2, 4, 1, 3])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank" title="sympy.combinatorics.permutations.Permutation.rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.next_lex" title="sympy.combinatorics.permutations.Permutation.next_lex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next_lex</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.unrank_nonlex">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">unrank_nonlex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">r</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L1754-L1785"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.unrank_nonlex" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a linear time unranking algorithm that does not
respect lexicographic order [3].</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">unrank_nonlex</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">Permutation([2, 0, 3, 1])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">unrank_nonlex</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">Permutation([0, 1, 2, 3])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.next_nonlex" title="sympy.combinatorics.permutations.Permutation.next_nonlex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next_nonlex</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank_nonlex" title="sympy.combinatorics.permutations.Permutation.rank_nonlex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank_nonlex</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Permutation.unrank_trotterjohnson">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">unrank_trotterjohnson</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rank</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L2526-L2562"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Permutation.unrank_trotterjohnson" title="Permalink to this definition">¶</a></dt>
<dd><p>Trotter Johnson permutation unranking. See [4] section 2.4.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Permutation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.interactive</span> <span class="kn">import</span> <span class="n">init_printing</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">init_printing</span><span class="p">(</span><span class="n">perm_cyclic</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">pretty_print</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Permutation</span><span class="o">.</span><span class="n">unrank_trotterjohnson</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="go">Permutation([0, 3, 1, 2, 4])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.rank_trotterjohnson" title="sympy.combinatorics.permutations.Permutation.rank_trotterjohnson"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rank_trotterjohnson</span></code></a>, <a class="reference internal" href="#sympy.combinatorics.permutations.Permutation.next_trotterjohnson" title="sympy.combinatorics.permutations.Permutation.next_trotterjohnson"><code class="xref py py-obj docutils literal notranslate"><span class="pre">next_trotterjohnson</span></code></a></p>
</div>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Cycle">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.permutations.</span></span><span class="sig-name descname"><span class="pre">Cycle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L242-L468"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Cycle" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapper around dict which provides the functionality of a disjoint cycle.</p>
<p class="rubric">Explanation</p>
<p>A cycle shows the rule to use to move subsets of elements to obtain
a permutation. The Cycle class is more flexible than Permutation in
that 1) all elements need not be present in order to investigate how
multiple cycles act in sequence and 2) it can contain singletons:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Perm</span><span class="p">,</span> <span class="n">Cycle</span>
</pre></div>
</div>
<p>A Cycle will automatically parse a cycle given as a tuple on the rhs:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">(1 3 2)</span>
</pre></div>
</div>
<p>The identity cycle, Cycle(), can be used to start a product:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Cycle</span><span class="p">()(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">(1 3 2)</span>
</pre></div>
</div>
<p>The array form of a Cycle can be obtained by calling the list
method (or passing it to the list function) and all elements from
0 will be shown:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
<span class="go">[0, 2, 1]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="go">[0, 2, 1]</span>
</pre></div>
</div>
<p>If a larger (or smaller) range is desired use the list method and
provide the desired size – but the Cycle cannot be truncated to
a size smaller than the largest element that is out of place:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">Cycle</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
<span class="go">[0, 2, 1, 3, 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">size</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">[0, 2, 1, 3, 4, 5]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">[0, 2, 1]</span>
</pre></div>
</div>
<p>Singletons are not shown when printing with one exception: the largest
element is always shown – as a singleton if necessary:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">10</span><span class="p">)(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">(1 5 4 10)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">4</span><span class="p">)(</span><span class="mi">5</span><span class="p">)(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">(1 2)(10)</span>
</pre></div>
</div>
<p>The array form can be used to instantiate a Permutation so other
properties of the permutation can be investigated:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Perm</span><span class="p">(</span><span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">list</span><span class="p">())</span><span class="o">.</span><span class="n">transpositions</span><span class="p">()</span>
<span class="go">[(1, 2), (3, 4)]</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>The underlying structure of the Cycle is a dictionary and although
the __iter__ method has been redefined to give the array form of the
cycle, the underlying dictionary items are still available with the
such methods as items():</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">Cycle</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
<span class="go">[(1, 2), (2, 1)]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation" title="sympy.combinatorics.permutations.Permutation"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Permutation</span></code></a></p>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations.Cycle.list">
<span class="sig-name descname"><span class="pre">list</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L352-L383"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations.Cycle.list" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the cycles as an explicit list starting from 0 up
to the greater of the largest value in the cycles and size.</p>
<p>Truncation of trailing unmoved items will occur when size
is less than the maximum element in the cycle; if this is
desired, setting <code class="docutils literal notranslate"><span class="pre">size=-1</span></code> will guarantee such trimming.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">Cycle</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Cycle</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
<span class="go">[0, 1, 3, 2, 5, 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="go">[0, 1, 3, 2, 5, 4, 6, 7, 8, 9]</span>
</pre></div>
</div>
<p>Passing a length too small will trim trailing, unchanged elements
in the permutation:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Cycle</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="go">[0, 2, 1]</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.combinatorics.permutations._af_parity">
<span class="sig-prename descclassname"><span class="pre">sympy.combinatorics.permutations.</span></span><span class="sig-name descname"><span class="pre">_af_parity</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pi</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/permutations.py#L114-L150"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.permutations._af_parity" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the parity of a permutation in array form.</p>
<p class="rubric">Explanation</p>
<p>The parity of a permutation reflects the parity of the
number of inversions in the permutation, i.e., the
number of pairs of x and y such that x &gt; y but p[x] &lt; p[y].</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.permutations</span> <span class="kn">import</span> <span class="n">_af_parity</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_af_parity</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_af_parity</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
<span class="go">1</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.permutations.Permutation" title="sympy.combinatorics.permutations.Permutation"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Permutation</span></code></a></p>
</div>
</dd></dl>

<section id="module-sympy.combinatorics.generators">
<span id="generators"></span><span id="combinatorics-generators"></span><h2>Generators<a class="headerlink" href="#module-sympy.combinatorics.generators" title="Permalink to this headline">¶</a></h2>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.generators.symmetric">
<span class="sig-prename descclassname"><span class="pre">generators.</span></span><span class="sig-name descname"><span class="pre">symmetric</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/generators.py#L7-L19"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.generators.symmetric" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates the symmetric group of order n, Sn.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.generators</span> <span class="kn">import</span> <span class="n">symmetric</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">symmetric</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="go">[(2), (1 2), (2)(0 1), (0 1 2), (0 2 1), (0 2)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.generators.cyclic">
<span class="sig-prename descclassname"><span class="pre">generators.</span></span><span class="sig-name descname"><span class="pre">cyclic</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/generators.py#L22-L42"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.generators.cyclic" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates the cyclic group of order n, Cn.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.generators</span> <span class="kn">import</span> <span class="n">cyclic</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">cyclic</span><span class="p">(</span><span class="mi">5</span><span class="p">))</span>
<span class="go">[(4), (0 1 2 3 4), (0 2 4 1 3),</span>
<span class="go"> (0 3 1 4 2), (0 4 3 2 1)]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.generators.dihedral" title="sympy.combinatorics.generators.dihedral"><code class="xref py py-obj docutils literal notranslate"><span class="pre">dihedral</span></code></a></p>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.generators.alternating">
<span class="sig-prename descclassname"><span class="pre">generators.</span></span><span class="sig-name descname"><span class="pre">alternating</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/generators.py#L45-L59"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.generators.alternating" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates the alternating group of order n, An.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.generators</span> <span class="kn">import</span> <span class="n">alternating</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">alternating</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="go">[(2), (0 1 2), (0 2 1)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.combinatorics.generators.dihedral">
<span class="sig-prename descclassname"><span class="pre">generators.</span></span><span class="sig-name descname"><span class="pre">dihedral</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/combinatorics/generators.py#L62-L95"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.combinatorics.generators.dihedral" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates the dihedral group of order 2n, Dn.</p>
<p>The result is given as a subgroup of Sn, except for the special cases n=1
(the group S2) and n=2 (the Klein 4-group) where that’s not possible
and embeddings in S2 and S4 respectively are given.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.combinatorics.generators</span> <span class="kn">import</span> <span class="n">dihedral</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">dihedral</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>
<span class="go">[(2), (0 2), (0 1 2), (1 2), (0 2 1), (2)(0 1)]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.combinatorics.generators.cyclic" title="sympy.combinatorics.generators.cyclic"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cyclic</span></code></a></p>
</div>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Permutations</a><ul>
<li><a class="reference internal" href="#module-sympy.combinatorics.generators">Generators</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="partitions.html"
                        title="previous chapter">Partitions</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="perm_groups.html"
                        title="next chapter">Permutation Groups</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/combinatorics/permutations.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="perm_groups.html" title="Permutation Groups"
             >next</a> |</li>
        <li class="right" >
          <a href="partitions.html" title="Partitions"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Combinatorics</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Permutations</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/combinatorics/permutations.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:26:03 GMT -->
</html>